package org.jackysoft.struts2.admin;

import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.annotations.Logger;
import org.jackysoft.entity.AcegiRole;
import org.jackysoft.entity.User;
import org.jackysoft.service.SecurityRoleService;
import org.jackysoft.struts2.UtilsCRUDAction;
import org.jackysoft.util.OperationType;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;




@Controller
@Namespace("/admin/securole")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Logger(label="授权",logType=OperationType.System)
public class SecuRoleAction extends UtilsCRUDAction<AcegiRole> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1983393989814435070L;
	private SecurityRoleService service;
	private AcegiRole bean;
	private Collection<AcegiRole> beans;
	private User user;
	private Collection<User> users;
			
	public String byuser() throws Exception{
	    beans = service.gets(user);
		return BEANLIST;
	}
	
	public String priority() throws Exception{
		beans = service.gets();
		return "priority";
	}
	
	public String apply() throws Exception{
		service.apply(bean);
		return "apply";
	}
	
	public String savepriority() throws Exception{
	    service.updatePriority(beans);
		return SUCCESS;
	}
	
	public String appenduser() throws Exception{
		service.appendUsers(bean, users);
		return SUCCESS;
	}
	
	public AcegiRole getBean() {
		return bean;
	}

	public void setBean(AcegiRole bean) {
		this.bean = bean;
	}

	public Collection<AcegiRole> getBeans() {
		return beans;
	}

	public void setBeans(Collection<AcegiRole> beans) {
		this.beans = beans;
	}

	public SecurityRoleService getService() {
		return service;
	}
	
    @Resource
	public void setService(SecurityRoleService service) {
		this.service = service;
		this.setDataProvider(service);
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Collection<User> getUsers() {
		return users;
	}

	public void setUsers(Collection<User> users) {
		this.users = users;
	}	

}
